<template>
  <div id="globalHeader">
    <a-row :wrap="false">
      <a-col flex="300px">
        <div class="title-bar">
          <img class="logo" src="../assets/logo.png" alt="logo" />
          <div class="title">贫困地区查询系统</div>
        </div>
      </a-col>
      <a-col flex="auto">
        <a-menu mode="horizontal" :items="items" @click="doMenuClick" />
      </a-col>
      <a-col flex="80px">
        <a-button type="primary" href="/user/login" ghost>登录</a-button>
      </a-col>
    </a-row>
  </div>
</template>
<script lang="ts" setup>
import { h, ref } from "vue";
import { HomeOutlined, CrownOutlined } from "@ant-design/icons-vue";
import { MenuProps } from "ant-design-vue";
import { useRouter } from "vue-router";
import { useLoginUserStore } from "@/store/useLoginUserStore";

const router = useRouter();

const loginUserStore = useLoginUserStore();

const doMenuClick = ({ key }: { key: string }) => {
  router.push({
    path: key,
  });
};
const current = ref<string[]>(["/"]);
//每次到新页面时都会执行这个函数
//监听路由变化，更新菜单选中状态
router.afterEach((to, from) => {
  current.value = [to.path];
});

const items = ref<MenuProps["items"]>([
  {
    key: "/",
    icon: () => h(HomeOutlined),
    label: "主页",
    title: "主页",
  },
  {
    key: "/user/login",
    label: "用户登录",
    title: "用户登录",
  },
  {
    key: "/user/register",
    label: "用户注册",
    title: "用户注册",
  },
  {
    key: "/admin/userManage",
    icon: () => h(CrownOutlined),
    label: "用户管理",
    title: "用户管理",
  },
  {
    key: "other",
    label: h("a", { href: "https://antdv.com", target: "_blank" }, "其他跳转"),
    title: "其他跳转",
  },
]);
</script>
<style scoped>
.title-bar {
  display: flex;
  align-items: center;
}

.title {
  color: black;
  font-size: 18px;
  margin-left: 16px;
}

.logo {
  height: 48px;
}
</style>
